package com.example.demo;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @author yujie
 * @create 2018-01-12 下午12:13
 **/

@Aspect
@Component
public class TestAspect {


    @Around("execution(* com.example.demo.service.TestUserService.*(..))")
    public Object Interceptor(ProceedingJoinPoint pjp) throws Throwable {
        //指定拦截器规则；也可以直接把“execution(* com.xjj.........)”写进这里
        long startTime = System.currentTimeMillis();
        Object obj;
        obj = pjp.proceed();
        /**
         * 切面一定要抛出异常
         */
        long endTime = System.currentTimeMillis();
        long totalTime = endTime - startTime;
        System.out.println(totalTime);
        return obj;
    }
}
